package www.yingdi365.com.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import www.yingdi365.com.R;
import www.yingdi365.com.base.ZjbBaseActivity;
import www.yingdi365.com.constant.Constant;

public class BianJiWXBMZActivity extends ZjbBaseActivity implements View.OnClickListener {
    private EditText editWeiXiangBenMC;
    private EditText editWeiXiangBenMS;
    private TextView textCount;
    private TextView textViewRight;
    private String name;
    private String des;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bian_ji_wxbmz);
        init();
    }

    @Override
    protected void initSP() {

    }

    @Override
    protected void initIntent() {
        Intent intent = getIntent();
        name = intent.getStringExtra(Constant.INTENT_KEY.Name);
        des = intent.getStringExtra(Constant.INTENT_KEY.Des);
    }

    @Override
    protected void findID() {
        editWeiXiangBenMC = (EditText) findViewById(R.id.editWeiXiangBenMC);
        editWeiXiangBenMS = (EditText) findViewById(R.id.editWeiXiangBenMS);
        textCount = (TextView) findViewById(R.id.textCount);
        textViewRight = (TextView) findViewById(R.id.textViewRight);
    }

    @Override
    protected void initViews() {
        ((TextView) findViewById(R.id.textViewTitle)).setText("创建微相本");
        textViewRight.setText("完成");
        editWeiXiangBenMC.setText(name);
        editWeiXiangBenMC.setSelection(name.length());
        editWeiXiangBenMS.setText(des);
        editWeiXiangBenMS.setSelection(des.length());
    }

    @Override
    protected void setListeners() {
        findViewById(R.id.imageBack).setOnClickListener(this);
        textViewRight.setOnClickListener(this);
        editWeiXiangBenMS.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                textCount.setText(s.length() + "/140");
            }
        });
    }


    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.textViewRight:
                if (TextUtils.isEmpty(editWeiXiangBenMC.getText().toString().trim())) {
                    Toast.makeText(BianJiWXBMZActivity.this, "请输入微相本名称", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(editWeiXiangBenMS.getText().toString().trim())) {
                    Toast.makeText(BianJiWXBMZActivity.this, "请输入微相本描述", Toast.LENGTH_SHORT).show();
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra(Constant.INTENT_KEY.Name, editWeiXiangBenMC.getText().toString().trim());
                intent.putExtra(Constant.INTENT_KEY.Des, editWeiXiangBenMS.getText().toString().trim());
                setResult(Constant.REQUEST_RESULT_CODE.XiuGaiMingZi, intent);
                finish();
                break;
            case R.id.imageBack:
                finish();
                break;
        }
    }
}
